import { Injectable, Optional } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { Observable } from 'rxjs/Observable';

export let urlBase = environment.urlBase || '/srm-manager/';

@Injectable()
export class HttpService {

    constructor(private http: HttpClient) { }

    get host() {
        // console.log(this.http.get);
        return 'http service ready';
    }

    get(url, options: any) {
        // options.responseType = 'json';
        return this.http.get<Response>(urlBase + url, options);
    }

    post(url, data, options?: {
        headers?: HttpHeaders;
        observe?: 'body';
        params?: HttpParams;
        reportProgress?: boolean;
        withCredentials?: boolean;
    }) {
        return this.http.post<Response>(urlBase + url, data, options || {});
    }

    get BaseUrl() {
        return urlBase;
    }

    // getUrl(url, options?) {
    //     let params = '';
    //     if (options) {
    //         params = '?' + Object.keys(options).map(x => {
    //             let val = options[x];
    //             if (typeof val !== 'string') {
    //                 val = JSON.stringify(val);
    //             }
    //             return x + '=' + encodeURIComponent(val);
    //         }).join('&');
    //     }
    //     return urlBase + url + params;
    // }
}
